namespace Vanilla.Tools.Init

import Vanilla.UI
import Vanilla

// Class defining the main menu button [ie, what would be the start menu on Windows]
class MainMenuButton (Button):
	// We store the menu here. It is fine to have a variable with the same name as the type it is.
	Menu as Menu

	// Overriding is when a class we inherit from [in this case Button, and the classes it inherits from] defines something, and we redefine it
	// specific to this class.
	// This specific example is a property. It is accessed just like e.g. the Menu above (ie, x = MinSize), however we have code that gets
	// and/or sets the value.
	// MinSize is the smallest size the gadget can be.
	override MinSize as Size:
		// Code to get the value
		get:
			// creates a Size of 30 width and 30 height, and returns it
			return Size(30,30)

	// Constructor - create the main menu button. p is the gadget we want this one created inside.
	def constructor (p as Box):
		// Call Button's constructor [well, one of them], which takes the parent gadget and an action as arguments.
		// In boo, {blah blah} denotes an action. If we used {print "whoop"}, "whoop" would be printed to the console when it was
		// clicked. But PopUp(blah) pops the given menu up over this gadget.
		super(p,{PopUp(Menu)})
		
		// Our menu = a new menu
		Menu = Menu()
		// Add an item. AddItem takes a string - the label given to the item, and an action -what to do when it's clicked.
		// Here, the action creates a new label with text "Label" in a new frame in a new window with title "Window with label"
		Menu.AddItem("New window with label", {Vanilla.UI.Label(Frame(Window("Window with label")), "Label")})
		// ... create a button with text "Button" that writes "You clic..." when pressed, inside a window with title "Window with button"
		Menu.AddItem("New window with button", {Button(Window("Window with button"), "Button", {print "You clicked button!"})})
		// If a {...} needs to span multiple lines, we can instead just skip it, then put "def ():" at the end of the line, and it can now
		// span multiple lines (until it's unindented again).
		Menu.AddItem("New window with buttons") def():
			// Create the window
			w = Window("Window with buttons")
			// Create a row inside the window
			c = Row(w)
			// Create 3 buttons inside the row
			Button(c, "1", {print "1"})
			Button(c, "2", {print "2"})
			Button(c, "3", {print "3"})
			// Create a column inside the row
			r = Column(c)
			// Create 3 buttons inside that column
			Button(r, "A", {print "A"})
			Button(r, "B", {print "B"})
			Button(r, "C", {print "C"})
		Menu.AddItem("Pointless zooming") def ():
			w = Window("Pointless zooming")
			z = ZoomGadget(w)
			c = Column(z)
			Button(c, "Whoooop", {print "Whoooop"})
			Button(c, "Chicken?", {print "Yummmy"})
		Menu.AddItem("Tools", {(UI.Tool.LoadTool(File("Vanilla.NET/Filer.tool")) as IOpenFile).OpenFile(File("Vanilla.NET"))})
		//Menu.AddItem("------------------------------------", {print ""})
		//Menu.AddItem("Vintage Theme", {Desktop.Theme = VintageTheme()}) 
		//Menu.AddItem("Default Theme", {Desktop.Theme = DefaultTheme()})
		//Menu.AddItem("Chocolate Theme", {Desktop.Theme = ChocolateTheme()})
		//Menu.AddItem("Vision Theme", {Desktop.Theme = VisionTheme()})
		//Menu.AddItem("Shine Theme", {Desktop.Theme = ShineTheme()})
		//Menu.AddItem("Eclipse Theme", {Desktop.Theme = EclipseTheme()})
		//Menu.AddItem("Wire Frame", {Desktop.Theme = FrameTheme()})
		Menu.AddItem("------------------------------------", {print ""})
		Menu.AddItem("Save Screenshot (after 2 seconds)") def ():
			UITimer (2000) def (t as UITimer):
				cv = BitmapCanvas(UI.Tool.CurrentDesktop.Size.Width, UI.Tool.CurrentDesktop.Size.Height)
				br = Brush(cv)
				UI.Tool.CurrentDesktop.Draw(br)
				cv.WriteToPNG("screenshot.png")
				t.Stop()
		Menu.AddItem("Toggle wallpaper") def ():
			if WallpaperEnabled:
				UI.Tool.CurrentDesktop.Remove(UI.Tool.CurrentDesktop.Background)
				WallpaperEnabled = false
			else:
				UI.Tool.CurrentDesktop.Background = ImageGadget(UI.Tool.CurrentDesktop, File("Wallpapers/Default.png"))
				WallpaperEnabled = true
		/*
		Menu.AddItem("Zoom In", {DesktopZoom.Scale = 1.2})
		Menu.AddItem("Zoom Out", {DesktopZoom.Scale = 0.8})
		*/
		Menu.AddItem("Quit", UI.Tool.Quit)
	
	WallpaperEnabled = true
	
	//public static DesktopZoom as ZoomGadget
	
	// Draws the button. b is an object we can use to draw with.
	override def Draw (b as Brush):
		// The line width = 3 pixels
		b.LineWidth = 3
		// If the mouse is currently over this button, use the colour blue
		if ContainsMouse:
			b.Colour = Colour.Blue
		// Otherwise, use grey
		else:
			b.Colour = Colour.Grey
		// Go to half way across the gadget's size, and 3 pixels from the top
		b.MoveTo(Size.Width/2, 3)
		// Draw a line to the bottom right
		b.LineTo(Size.Width-3, Size.Height-3)
		// From there, draw a line to the bottom left
		b.LineTo(3, Size.Height-3)
		// Then back to the centre of the top
		b.LineTo(Size.Width/2, 3)
		// And stroke what we've just drawn [ie, actually draw it]
		b.Stroke()

class InitTool (UI.Tool, IOpen):
	def Open ():
		MainMenuButton(UI.Tool.CurrentDesktop.Panel.Left)
		
